package com.ruoyi.mq;

import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;


@Component
@AllArgsConstructor
public class DelayQueueManager {

    private static final String key = "faceTaskQueue";

    private final RedisTemplate<String, String> redisTemplate;

    public void addToDelayQueue(String value, long delayMillis) {
        redisTemplate.opsForZSet().add(key, value, System.currentTimeMillis() + delayMillis);
    }

    public Set<String> getExpiredItems(long currentTime) {
        return redisTemplate.opsForZSet().rangeByScore(key, 0, currentTime);
    }

    public void removeItems(Set<String> items) {
        redisTemplate.opsForZSet().remove(key, items.toArray());
    }
}

